"use strict";

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var Page = function () {
	function Page(options) {
		_classCallCheck(this, Page);

		this.list = options.list;
		this.url = options.url;

		this.load();
		this.addEvent();
	}

	_createClass(Page, [{
		key: "load",
		value: function load() {
			var that = this;
			$.ajax({
				url: this.url,

				success: function success(res) {
					console.log(res), that.res = res;
					that.display();
				}
			});
		}
	}, {
		key: "display",
		value: function display() {
			var str = "";
			for (var i = 0; i < this.res[1].length; i++) {
				//					if(i<this.res.length){
				str += "<li index=\"" + this.res[1][i].id + "\">\n\t\t\t\t\t\t\t\t<a><img src=\"" + this.res[1][i].img + "\"/ ></a>\n\t\t\t\t\t\t\t\t<a><h3>" + this.res[1][i].info + "</h3></a>\n\t\t\t\t\t\t\t\t<span>\xA5" + this.res[1][i].price + "</span>\n\t\t\t\t\t\t\t</li>";
				//					}
			}
			this.list.html(str);
			console.log(this.list);
		}
	}, {
		key: "addEvent",
		value: function addEvent() {
			var obj = $.cookie;
			var that = this;
			this.list.on("click", "li", function () {

				var a = $(this).attr("index");

				obj("goodsdetail", a);
				location.href = "goodsdetail.html";
			});
		}
	}]);

	return Page;
}();

new Page({
	list: $("article").children("ul.xia"),
	url: "data/goods.json"

});
//		
$(function () {
	$(".louti ul").children("li").not(":first-child").click(function () {
		//				$(this).index()//返回当前li的索引

		//				$(document).scrollTop($("div").eq($(this).index()).offset().top)
		$("html").stop().animate({
			scrollTop: $(".louceng1").eq($(this).index() - 1).offset().top
		});

		$(this).css({
			background: "#157cdb",
			color: "#fff"
		}).siblings().css({
			background: "#fff",
			color: "#5e5e5e"
		});
	});
	$(".louti ul").children("li:first-child").click(function () {
		//				console.log(this.)
		$("html").stop().animate({
			scrollTop: $("#specialAds").offset().top
		});
	});

	//			if($("html").scrollTop = $(".louceng1").eq($(this).index()-1).offset().top){
	//				console.log()
	//			}


	$(window).scroll(function () {
		//				console.log($("html").scrollTop())
		for (var i = 0; i < $(".louti ul li").length - 1; i++) {
			var a = $("html").scrollTop();
			var b = $(".louceng1").eq(i).offset().top;
			if (a - b >= -100 && a - b <= 100) {
				$(".louti ul li").eq(i + 1).css({
					background: "#157cdb",
					color: "#fff"
				}).siblings().css({
					background: "#fff",
					color: "#5e5e5e"
				});
			}
		}
	});
});